<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/inc/taglib.jsp"%>
<style>
.buttonRight {
	left: 555px;
	bottom: -18.9px;
	margin-left: 10px;
}
</style>
<div class="pageContent">
	<form method="post" action="${pageContext.request.contextPath}${requestScope.record ==null ?'/warehouse/wareTransferOrder/insert' :'/warehouse/wareTransferOrder/update' }" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<div class="pageFormContent" layoutH="56">
			<!-- 关闭窗口 -->
			<input type="hidden" name="callbackType" value="closeCurrent" />
			<!-- 隐藏表单 -->
			<c:if test="${requestScope.record !=null}">
				<input type="hidden" name="id" value="${requestScope.record.id}" />
			</c:if>
			<fieldset>
				<legend>调拨单</legend>
				<p>
					<label>订单编号</label><input name="onum" class="required" maxlength="50" type="text" value="${requestScope.record.onum}" />
				</p>
				<p>
					<label>备注</label><input name="orderRemk" class="required" maxlength="50" type="text" value="${requestScope.record.remk}" />
				</p>
			</fieldset>
			<fieldset>
				<legend>调拨内容</legend>
				<div id="parameter" class="nowrap" style="margin-left: auto; margin-right: auto;">
					<a class="button buttonRight" href="javascript:addParameter();"><span>＋添加</span></a>
					<!-- 没数据是显示 -->
					<c:if test="${fn:length(requestScope.orderDetails)==0}">
						<div class="unit">
							<label style="width: 95px;">商品名称</label> 
							<select style="width: 160px;" name="pnid" onchange="changeVal(this)">
								<option value="">请选择</option>
								<c:forEach items="${requestScope.productNorms}" var="norms">
									<option value="${norms.merchantProductNormId}">${norms.normName}</option>
								</c:forEach>
							</select> 
							<label style="width: 65px;">调出仓库</label> 
							<select style="width: 70px;" name="owid">
								<option value="">请选择</option>
								<c:forEach items="${requestScope.warehouses}" var="witems">
									<option value="${witems.id}">${witems.name}</option>
								</c:forEach>
							</select> 
							<label style="width: 65px;">调入仓库</label> 
							<select style="width: 70px;" name="iwid">
								<option value="">请选择</option>
								<c:forEach items="${requestScope.warehouses}" var="witems">
									<option value="${witems.id}">${witems.name}</option>
								</c:forEach>
							</select> 
							
							<label style="width: 35px;">规格</label> <input name="pack" type="text" readonly="readonly" style='background-color: #f6f6f6;' value=""> 
							<label style="width: 35px;">单位</label> <input name="capacity" type="text" readonly="readonly" style='background-color: #f6f6f6;' value=""> 
							
							
							<label style="width: 33px;">数量</label><input type="text" name="amut" class="textInput" value=""> 
							<label style="width: 33px;">备注</label><input type="text" name="remk" maxlength="500" class="textInput" value=""> 
							<a class="button buttonRight" href="javascript:void()" onclick="delParameter(this)"><span>-删除</span></a>
						</div>
					</c:if>
					<c:forEach items="${requestScope.orderDetails }" var="item" varStatus="status">
						<div class="unit">
							<input type="hidden" name="wtoodid" value="${item.id}"> 
							<label style="width: 95px;">商品名称</label> 
							<select style="width: 160px;" name="pnid" onchange="changeVal(this)">
								<option value="">请选择</option>
								<c:forEach items="${requestScope.productNorms}" var="norms">
									<option value="${norms.merchantProductNormId}" ${item.pnid == norms.merchantProductNormId?'selected':''}>${norms.normName}</option>
								</c:forEach>
							</select> 
							<label style="width: 65px;">调出仓库</label> 
							<select style="width: 70px;" name="owid">
								<option value="">请选择</option>
								<c:forEach items="${requestScope.warehouses}" var="witems">
									<option value="${witems.id}" ${item.owid == witems.id?'selected':''}>${witems.name}</option>
								</c:forEach>
							</select> 
							<label style="width: 65px;">调入仓库</label> 
							<select style="width: 70px;" name="iwid">
								<option value="">请选择</option>
								<c:forEach items="${requestScope.warehouses}" var="witems">
									<option value="${witems.id}" ${item.iwid == witems.id?'selected':''}>${witems.name}</option>
								</c:forEach>
							</select> 
							
							<label style="width: 35px;">规格</label> <input name="pack" type="text" readonly="readonly" style='background-color: #f6f6f6;' value="${item.pack}"> 
							<label style="width: 35px;">单位</label> <input name="capacity" type="text" readonly="readonly" style='background-color: #f6f6f6;' value="${item.capacity}"> 
							
							<label style="width: 33px;">数量</label><input type="text" name="amut" maxlength="11" class="textInput" value="${item.amut}"> 
							<label style="width: 33px;">备注</label><input type="text" name="remk" maxlength="500" class="textInput" value="${item.remk}">
							<a class="button buttonRight" href="javascript:void()" onclick="delParameter(this)"><span>-删除</span></a>
						</div>
					</c:forEach>
				</div>
			</fieldset>
		</div>
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive">
						<div class="buttonContent">
							<button type="submit">保存</button>
						</div>
					</div></li>
				<li>
					<div class="button">
						<div class="buttonContent">
							<button type="button" class="close">取消</button>
						</div>
					</div>
				</li>
			</ul>
		</div>
	</form>
</div>
<script type="text/javascript">
	function addParameter() {
		$("#parameter").append("<div class='unit'><input type='hidden' name='wioodid'>" + "<label style='width: 95px;'>商品名称</label><select name='pnid' class='' onchange='changeVal(this)' >" + "<option value=''>请选择</option>" + "<c:forEach items='${requestScope.productNorms}' var='norms'>" + "<option value='${norms.merchantProductNormId}'>${norms.normName}</option>" + "</c:forEach>" + "</select>"

		+ "<label style='width: 65px;'>调出仓库</label>                    " + "<select name='owid'>                                            " + "	<option value=''>请选择</option>                            " + "	<c:forEach items='${requestScope.warehouses}' var='witems'> " + "		<option value='${witems.id}'>${witems.name}</option>    " + "	</c:forEach>                                                " + "</select>                                                       " + "<label style='width: 65px;'>调入仓库</label>                    " + "<select name='iwid'>                                            " + "	<option value=''>请选择</option>                            " + "	<c:forEach items='${requestScope.warehouses}' var='witems'> " + "		<option value='${witems.id}'>${witems.name}</option>    " + "	</c:forEach>                                                " + "</select>                                                       "

		+"<label style='width: 35px;'>规格</label> <input name='pack' type='text' class='textInput' readonly='readonly' style='background-color: #f6f6f6;' value=''>    "
		+"<label style='width: 35px;'>单位</label> <input name='capacity' type='text' class='textInput' readonly='readonly' style='background-color: #f6f6f6;' value=''>" 
		
		
		+ "<label style='width: 33px;'>数量</label><input class='textInput' type='text' name='amut' maxlength='11' value=''>"

		+ "<label style='width: 33px;'>备注</label><input type='text' name='remk' maxlength='500' class='textInput' value=''> "
		+ "<a class='button buttonRight' href='javascript:void()' onclick='delParameter(this)'><span>-删除</span></a>"
		+ "</div>");
	}
	function delParameter(obj) {
		$(obj).parent().remove();
	}
	function changeVal(e) {
		var pnid = $(e).parent().find("[name='pnid']").val();

		var data = {
			pnid : pnid
		}; 
		if(pnid){
			$.ajax({
				//type : form.method || 'POST',
				url : "${pageContext.request.contextPath}/merchant/merchantProductNorm/getMerchantProductNorm",
				//获取表单的内容数据  
				data : data,
				//dataType : "json",
				//cache : false,
				//执行回调函数  
				success : function(result) {
					var code = result.statusCode;
					var msg = result.message;
					if (code == 200) {
						var content = result.content;
						$(e).parent().find("[name='pack']").val(content.pack);
						$(e).parent().find("[name='capacity']").val(content.capacity);
						
					}
					if (code == 300) {
						alertMsg.warn(msg);
					}
				},
				error : function(result) {
					alert(result)
				}
			});
		}
	}
</script>